library(haven)
library(MASS)
library(Zelig)
library(ZeligChoice)
library(stargazer)
library(ggplot2)
library(corrplot)
library(psy)
library(readxl)
library(sjPlot)
library(effects)
library(psych)
library(dplyr)
library(REdaS)

## READ IN CMPS DATA
#cmps <- read.csv("C:/Users/natha/Documents/cmps2016.csv")

## RECODE CONTROLS AND DEMOGRAPHICS
cmps$citizen <- NA
cmps$citizen <- as.numeric(cmps$citizen)
cmps$citizen[cmps$s7==1] <- 1
cmps$citizen[cmps$c375==1] <- 1
cmps$citizen[cmps$c375==2] <- 0
cmps$citizen[cmps$c375==3] <- 0
cmps$citizen[cmps$c375==4] <- 0
cmps$citizen[cmps$c375==5] <-0
cmps$citizen[cmps$c375==6] <- 0

cmps$income <- NA
cmps$income <- as.numeric(cmps$income)
cmps$income[cmps$c383==1] <- 0
cmps$income[cmps$c383==2] <- 0.09
cmps$income[cmps$c383==3] <- 0.18
cmps$income[cmps$c383==4] <- 0.27
cmps$income[cmps$c383==5] <- 0.36
cmps$income[cmps$c383==6] <- 0.45
cmps$income[cmps$c383==7] <- 0.54
cmps$income[cmps$c383==8] <- 0.63
cmps$income[cmps$c383==9] <- 0.72
cmps$income[cmps$c383==10] <- 0.81
cmps$income[cmps$c383==11] <-0.9
cmps$income[cmps$c383==12] <- 1
table(cmps$income)

cmps$american.id <- NA
cmps$american.id <- as.numeric(cmps$american.id)
cmps$american.id[cmps$c194==1] <- 1
cmps$american.id[cmps$c194==2] <- 0.667
cmps$american.id[cmps$c194==3] <- 0.333
cmps$american.id[cmps$c194==4] <- 0

cmps$non.straight <- NA
cmps$non.straight <- as.numeric(cmps$non.straight)
cmps$non.straight <- ifelse(cmps$c237==1,1,0)

cmps$racial.equity.achieved <- NA
cmps$racial.equity.achieved <- as.numeric(cmps$racial.equity.achieved)
cmps$racial.equity.achieved[cmps$bla146==1] <- 1        
cmps$racial.equity.achieved[cmps$bla146==2] <- 0.667
cmps$racial.equity.achieved[cmps$bla146==3] <- 0.333
cmps$racial.equity.achieved[cmps$bla146==4] <- 0

cmps$police.unfair <- NA
cmps$police.unfair <- as.numeric(cmps$police.unfair)
cmps$police.unfair[cmps$c280==1] <- 1
cmps$police.unfair[cmps$c280==2] <- 1
cmps$police.unfair[cmps$c280==3] <- 0

table(cmps$c380)
cmps$afro.latino <- NA
cmps$afro.latino <- as.numeric(cmps$afro.latino)
cmps$afro.latino[cmps$c380==1] <- 0
cmps$afro.latino[cmps$c380==2] <- 1

cmps$first.gen <- NA
cmps$first.gen <- cmps$first.gen
cmps$first.gen <- ifelse(cmps$s7==2|cmps$s7==3,1,0)
addmargins(table(cmps$first.gen))

cmps$second.gen <- NA
cmps$second.gen <- as.numeric(cmps$second.gen)
cmps$second.gen[cmps$c377==1] <- 0
cmps$second.gen[cmps$c377==2] <- 1
cmps$second.gen[cmps$c377==3] <- 1
cmps$second.gen[cmps$c377==4] <- 1
addmargins(table(cmps$second.gen))

cmps$third.gen <- NA
cmps$third.gen <- as.numeric(cmps$third.gen)
cmps$third.gen[cmps$c379==1] <- 0
cmps$third.gen[cmps$c379==2] <- 1
cmps$third.gen[cmps$c379==3] <- 1
cmps$third.gen[cmps$c379==4] <- 1
cmps$third.gen[cmps$c379==5] <- 1
addmargins(table(cmps$third.gen))

cmps$education <- NA
cmps$education <- as.numeric(cmps$education)
cmps$education[cmps$c381==1] <- 0
cmps$education[cmps$c381==2] <- 0.2
cmps$education[cmps$c381==3] <- 0.4
cmps$education[cmps$c381==4] <- 0.6
cmps$education[cmps$c381==5] <- 0.8
cmps$education[cmps$c381==6] <- 1

cmps$polinterest <- NA
cmps$polinterest <- as.numeric(cmps$polinterest)
cmps$polinterest[cmps$c33==3] <- 1
cmps$polinterest[cmps$c33==2] <- 0.667
cmps$polinterest[cmps$c33==1] <- 0.333
cmps$polinterest[cmps$c33==0] <- 0

cmps$age.new <- NA
cmps$age.new <- as.numeric(cmps$age)/100

cmps$intefficacy <- NA
cmps$intefficacy <- as.numeric(cmps$intefficacy)
cmps$intefficacy[cmps$c121==5] <- 1
cmps$intefficacy[cmps$c121==4] <- 0.75
cmps$intefficacy[cmps$c121==3] <- 0.5
cmps$intefficacy[cmps$c121==2] <- 0.25
cmps$intefficacy[cmps$c121==1] <- 0

#taken from question 
cmps$extefficacy <- NA
cmps$extefficacy <- as.numeric(cmps$extefficacy)
cmps$extefficacy[cmps$c106==1] <- 0
cmps$extefficacy[cmps$c106==2] <- 0.25
cmps$extefficacy[cmps$c106==3] <- 0.5
cmps$extefficacy[cmps$c106==4] <- 0.75
cmps$extefficacy[cmps$c106==5] <- 1

cmps$partystrength <- NA
cmps$partystrength <- as.numeric(cmps$partystrength)
cmps$partystrength[cmps$c25==1&cmps$c26==1] <- 1
cmps$partystrength[cmps$c25==2&cmps$c26==1] <- 1
cmps$partystrength[cmps$c25==1&cmps$c26==2] <- 0.667
cmps$partystrength[cmps$c25==2&cmps$c26==2] <- 0.667
cmps$partystrength[cmps$c25==3&cmps$c27==1] <- 0.333
cmps$partystrength[cmps$c25==3&cmps$c27==2] <- 0.333
cmps$partystrength[cmps$c25==3&cmps$c27==3] <- 0
cmps$partystrength[cmps$c25==4&cmps$c27==3] <- 0
addmargins(table(cmps$partystrength))

cmps$forborn <- NA
cmps$forborn <- as.numeric(cmps$forborn)
cmps$forborn[cmps$s7==1] <- 0
cmps$forborn[cmps$s7==2] <- 1
cmps$forborn[cmps$s7==3] <- 1

cmps$asian <- NA
cmps$asian <- as.numeric(cmps$asian)
cmps$asian[cmps$ethnic_quota==4] <- 1
cmps$asian[cmps$ethnic_quota==3] <- 0
cmps$asian[cmps$ethnic_quota==2] <- 0
cmps$asian[cmps$ethnic_quota==1] <- 0

cmps$latino <- NA
cmps$latino <- as.numeric(cmps$latino)
cmps$latino[cmps$ethnic_quota==4] <- 0
cmps$latino[cmps$ethnic_quota==3] <- 0
cmps$latino[cmps$ethnic_quota==2] <- 1
cmps$latino[cmps$ethnic_quota==1] <- 0

cmps$whites <- NA
cmps$whites <- as.numeric(cmps$whites)
cmps$whites[cmps$ethnic_quota==4] <- 0
cmps$whites[cmps$ethnic_quota==3] <- 0
cmps$whites[cmps$ethnic_quota==2] <- 0
cmps$whites[cmps$ethnic_quota==1] <- 1

cmps$chinese <- NA
cmps$chinese <- as.numeric(cmps$chinese)
cmps$chinese <- ifelse(cmps$s8==1,1,0)

cmps$taiwanese <- NA
cmps$taiwanese <- as.numeric(cmps$taiwanese)
cmps$taiwanese <- ifelse(cmps$s8==2,1,0)

cmps$indian <- NA
cmps$indian <- as.numeric(cmps$indian)
cmps$indian <- ifelse(cmps$s8==3,1,0)

cmps$korean <- NA
cmps$korean <- as.numeric(cmps$korean)
cmps$korean <- ifelse(cmps$s8==4,1,0)

cmps$filipino <- NA
cmps$filipino <- as.numeric(cmps$filipino)
cmps$filipino <- ifelse(cmps$s8==5,1,0)

cmps$vietnamese <- NA
cmps$vietnamese <- as.numeric(cmps$vietnamese)
cmps$vietnamese <- ifelse(cmps$s8==6,1,0)

cmps$japanese <- NA
cmps$japanese <- as.numeric(cmps$japanese)
cmps$japanese <- ifelse(cmps$s8==7,1,0)

cmps$colombian <- NA
cmps$colombian <- as.numeric(cmps$colombian)
cmps$colombian <- ifelse(cmps$s10==4,1,0)

cmps$cuban <- NA
cmps$cuban <- as.numeric(cmps$cuban)
cmps$cuban <- ifelse(cmps$s10==6,1,0)

cmps$dominican <- NA
cmps$dominican <- as.numeric(cmps$dominican)
cmps$dominican <- ifelse(cmps$s10==7,1,0)

cmps$mexican <- NA
cmps$mexican <- as.numeric(cmps$mexican)
cmps$mexican <- ifelse(cmps$s10==12,1,0)

cmps$puerto.rican <- NA
cmps$puerto.rican <- as.numeric(cmps$puerto.rican)
cmps$puerto.rican <- ifelse(cmps$s10==17,1,0)

cmps$spanish <- NA
cmps$spanish <- as.numeric(cmps$spanish)
cmps$spanish <- ifelse(cmps$s10==20,1,0)

cmps$ethnic.identity.latinos <- NA
cmps$ethnic.identity.latinos <- as.numeric(cmps$ethnic.identity.latinos)
cmps$ethnic.identity.latinos[cmps$l192==1] <- 1
cmps$ethnic.identity.latinos[cmps$l192==2] <- 0.667
cmps$ethnic.identity.latinos[cmps$l192==3] <- 0.333
cmps$ethnic.identity.latinos[cmps$l192==4] <- 0

cmps$ethnic.identity.asians <- NA
cmps$ethnic.identity.asians <- as.numeric(cmps$ethnic.identity.asians)
cmps$ethnic.identity.asians[cmps$a192==1] <- 1
cmps$ethnic.identity.asians[cmps$a192==2] <- 0.667
cmps$ethnic.identity.asians[cmps$a192==3] <- 0.333
cmps$ethnic.identity.asians[cmps$a192==4] <- 0

table(cmps$a195_3)
table(cmps$l195_3)
cmps$american.id.first.asians <- NA
cmps$american.id.first.asians <- as.numeric(cmps$american.id.first.asians)
cmps$american.id.first.asians <- ifelse(cmps$a195_3==3,1,0)

cmps$american.id.first.latinos <- NA
cmps$american.id.first.latinos <- as.numeric(cmps$american.id.first.latinos)
cmps$american.id.first.latinos <- ifelse(cmps$l195_3==3,1,0)

cmps$black.org <- NA
cmps$black.org <- as.numeric(cmps$black.org)
cmps$black.org[cmps$b143==1] <- 1
cmps$black.org[cmps$b143==2] <- 0

cmps$black.party <- NA
cmps$black.party <- as.numeric(cmps$black.party)
cmps$black.party[cmps$b153==1] <- 1
cmps$black.party[cmps$b153==2] <- 0.75
cmps$black.party[cmps$b153==3] <- 0.5
cmps$black.party[cmps$b153==4] <- 0.25
cmps$black.party[cmps$b153==5] <- 0

cmps$black.nation <- NA
cmps$black.nation <- as.numeric(cmps$black.nation)
cmps$black.nation[cmps$b154==1] <- 0
cmps$black.nation[cmps$b154==2] <- 1

cmps$black.econ.white <- NA
cmps$black.econ.white <- as.numeric(cmps$black.econ.white)
cmps$black.econ.white[cmps$b156==1] <- 0
cmps$black.econ.white[cmps$b156==2] <- 0.25
cmps$black.econ.white[cmps$b156==3] <- 0.50
cmps$black.econ.white[cmps$b156==4] <- 0.75
cmps$black.econ.white[cmps$b156==5] <- 1

cmps$black.racism <- NA
cmps$black.racism <- as.numeric(cmps$black.racism)
cmps$black.racism[cmps$bl155==1] <- 0
cmps$black.racism[cmps$bl155==2] <- 0.5
cmps$black.racism[cmps$bl155==3] <- 1

table(cmps$c53)
cmps$ce <- NA
cmps$ce <- as.numeric(cmps$ce)
cmps$ce[cmps$c53==3] <- 0
cmps$ce[cmps$c53==1&cmps$c54==2] <- 1
cmps$ce[cmps$c53==1&cmps$c54==1] <- 2
cmps$ce[cmps$c53==2&cmps$c54==2] <- 3
cmps$ce[cmps$c53==2&cmps$c54==1] <- 4
table(cmps$ce)

cmps$catholic <- NA
cmps$catholic <- as.numeric(cmps$catholic)
cmps$catholic[cmps$c129==1] <- 1
cmps$catholic[cmps$c129==2] <- 0
cmps$catholic[cmps$c129==3] <- 0
cmps$catholic[cmps$c129==4] <- 0
cmps$catholic[cmps$c129==5] <- 0
cmps$catholic[cmps$c129==6] <- 0
cmps$catholic[cmps$c129==7] <- 0
cmps$catholic[cmps$c129==8] <- 0
cmps$catholic[cmps$c129==9] <- 0

cmps$protestant <- NA
cmps$protestant <- as.numeric(cmps$protestant)
cmps$protestant[cmps$c129==1] <- 0
cmps$protestant[cmps$c129==2] <- 1
cmps$protestant[cmps$c129==3] <- 0
cmps$protestant[cmps$c129==4] <- 0
cmps$protestant[cmps$c129==5] <- 0
cmps$protestant[cmps$c129==6] <- 0
cmps$protestant[cmps$c129==7] <- 0
cmps$protestant[cmps$c129==8] <- 0
cmps$protestant[cmps$c129==9] <- 0

cmps$republican <- NA
cmps$republican <- as.numeric(cmps$republican)
cmps$republican[cmps$c25==1] <- 1
cmps$republican[cmps$c25==2] <- 0
cmps$republican[cmps$c25==3] <- 0
cmps$republican[cmps$c25==4] <- 0

cmps$democrat <- NA
cmps$democrat <- as.numeric(cmps$democrat)
cmps$democrat[cmps$c25==1] <- 0
cmps$democrat[cmps$c25==2] <- 1
cmps$democrat[cmps$c25==3] <- 0
cmps$democrat[cmps$c25==4] <- 0

cmps$conservative <- NA
cmps$conservative <- as.numeric(cmps$conservative)
cmps$conservative[cmps$c31==1] <- 0
cmps$conservative[cmps$c31==2] <- 0
cmps$conservative[cmps$c31==3] <- 0
cmps$conservative[cmps$c31==4] <- 1
cmps$conservative[cmps$c31==5] <- 1
cmps$conservative[cmps$c31==6] <- 0

cmps$churchattendance <- NA
cmps$churchattendance <- as.numeric(cmps$churchattendance)
cmps$churchattendance[cmps$c131==1] <-1
cmps$churchattendance[cmps$c131==2] <-0.8
cmps$churchattendance[cmps$c131==3] <-0.6
cmps$churchattendance[cmps$c131==4] <-0.4
cmps$churchattendance[cmps$c131==5] <- 0.2
cmps$churchattendance[cmps$c131==6] <- 0

cmps$black <- NA
cmps$black <- as.numeric(cmps$black)
cmps$black[cmps$ethnic_quota==1] <- 0
cmps$black[cmps$ethnic_quota==2] <- 0
cmps$black[cmps$ethnic_quota==3] <- 1
cmps$black[cmps$ethnic_quota==4] <- 0

cmps$trust <- NA
cmps$trust <- as.numeric(cmps$trust)
cmps$trust[cmps$c47==1] <- 1
cmps$trust[cmps$c47==2] <- 0.667
cmps$trust[cmps$c47==3] <- 0.333
cmps$trust[cmps$c47==4] <- 0

cmps$economy.worsened <- NA
cmps$economy.worsened <- as.numeric(cmps$economy.worsened)
cmps$economy.worsened[cmps$c23==1] <- 0
cmps$economy.worsened[cmps$c23==2] <- 0.25
cmps$economy.worsened[cmps$c23==3] <- 0.75
cmps$economy.worsened[cmps$c23==4] <- 1
cmps$economy.worsened[cmps$c23==5] <- 0.5

cmps$female <- NA
cmps$female <- as.numeric(cmps$female)
cmps$female <- ifelse(cmps$s3==1,1,0)

cmps$lf <- NA
cmps$lf <- as.numeric(cmps$lf)
cmps$lf[cmps$c150==2] <- 0
cmps$lf[cmps$c150==1&cmps$c151==1] <- 1
cmps$lf[cmps$c150==1&cmps$c151==2] <- 0.667
cmps$lf[cmps$c150==1&cmps$c151==3] <- 0.333

table(cmps$c243)
cmps$discr.whites <- NA
cmps$discr.whites <- as.numeric(cmps$discr.whites)
cmps$discr.whites[cmps$c243==1] <- 1
cmps$discr.whites[cmps$c243==2] <- 0.667
cmps$discr.whites[cmps$c243==3] <- 0.333
cmps$discr.whites[cmps$c243==4] <- 0

table(cmps$c244)
cmps$discr.blacks <- NA
cmps$discr.blacks <- as.numeric(cmps$discr.blacks)
cmps$discr.blacks[cmps$c244==1] <- 1
cmps$discr.blacks[cmps$c244==2] <- 0.667
cmps$discr.blacks[cmps$c244==3] <- 0.333
cmps$discr.blacks[cmps$c244==4] <- 0

cmps$discr.whites.blacks.diff <- NA
cmps$discr.whites.blacks.diff <- as.numeric(cmps$discr.whites.blacks.diff)
cmps$discr.whites.blacks.diff <- (cmps$discr.whites)-(cmps$discr.blacks)

cmps$discr.asians <- NA
cmps$discr.asians <- as.numeric(cmps$discr.asians)
cmps$discr.asians[cmps$c245==1] <- 1
cmps$discr.asians[cmps$c245==2] <- 0.667
cmps$discr.asians[cmps$c245==3] <- 0.333
cmps$discr.asians[cmps$c245==4] <- 0

cmps$discr.latinos <- NA
cmps$discr.latinos <- as.numeric(cmps$discr.latinos)
cmps$discr.latinos[cmps$c247==1] <- 0
cmps$discr.latinos[cmps$c247==2] <- 0.333
cmps$discr.latinos[cmps$c247==3] <- 0.667
cmps$discr.latinos[cmps$c247==4] <- 0

cmps$discr.personal <- NA
cmps$discr.personal <- as.numeric(cmps$discr.personal)
cmps$discr.personal[cmps$c251==1] <- 1 
cmps$discr.personal[cmps$c251==2] <- 0

cmps$race.perceived <- NA
cmps$race.perceived <- as.character(cmps$race.perceived)
cmps$race.perceived[cmps$c373==1] <- "1. White"
cmps$race.perceived[cmps$c373==2] <- "2. Black"
cmps$race.perceived[cmps$c373==3] <- "3. Latino"
cmps$race.perceived[cmps$c373==4] <- "4. Asian"
cmps$race.perceived[cmps$c373==5] <- "5. Other"
cmps$race.perceived[cmps$c373==6] <- "5. Other"
cmps$race.perceived[cmps$c373==7] <- "5. Other"

cmps$media.black <- NA
cmps$media.black <- as.numeric(cmps$media.black)
cmps$media.black[cmps$b24==1] <- 0.2
cmps$media.black[cmps$b24==2] <- 0.4
cmps$media.black[cmps$b24==3] <- 0.6
cmps$media.black[cmps$b24==4] <- 0.8
cmps$media.black[cmps$b24==5] <- 1
cmps$media.black[cmps$b24==6] <- 0

cmps$media.latino <- NA
cmps$media.latino <- as.numeric(cmps$media.latino)
cmps$media.latino[cmps$l24==1] <- 0.2
cmps$media.latino[cmps$l24==2] <- 0.4
cmps$media.latino[cmps$l24==3] <- 0.6
cmps$media.latino[cmps$l24==4] <- 0.8
cmps$media.latino[cmps$l24==5] <- 1
cmps$media.latino[cmps$l24==6] <- 0

cmps$media.asian <- NA
cmps$media.asian <- as.numeric(cmps$media.asian)
cmps$media.asian[cmps$a24==1] <- 0.2
cmps$media.asian[cmps$a24==2] <- 0.4
cmps$media.asian[cmps$a24==3] <- 0.6
cmps$media.asian[cmps$a24==4] <- 0.8
cmps$media.asian[cmps$a24==5] <- 1
cmps$media.asian[cmps$a24==6] <- 0


### MAIN INDEPENDENT VARIABLES: 
#c118: How often would you say public officials work work hard to help: 
table(cmps$c118)
cmps$racial.eff.officials <- NA
cmps$racial.eff.officials <- as.numeric(cmps$racial.eff.officials)
cmps$racial.eff.officials[cmps$c118==1] <- 1
cmps$racial.eff.officials[cmps$c118==2] <- 0.75
cmps$racial.eff.officials[cmps$c118==3] <- 0.5
cmps$racial.eff.officials[cmps$c118==4] <- 0.25
cmps$racial.eff.officials[cmps$c118==5] <- 0

#c119
cmps$racial.eff.government <- NA
cmps$racial.eff.government <- as.numeric(cmps$racial.eff.government)
cmps$racial.eff.government[cmps$c119==1] <- 1
cmps$racial.eff.government[cmps$c119==2] <- 0.75
cmps$racial.eff.government[cmps$c119==3] <- 0.5
cmps$racial.eff.government[cmps$c119==4] <- 0.25
cmps$racial.eff.government[cmps$c119==5] <- 0

#c120: How often would you say [INSERT ANSWER S2] elected to office can make changes for people in your racial group?
cmps$racial.eff.elected <- NA
cmps$racial.eff.elected <- as.numeric(cmps$racial.eff.elected)
cmps$racial.eff.elected[cmps$c120==1] <- 1
cmps$racial.eff.elected[cmps$c120==2] <- 0.75
cmps$racial.eff.elected[cmps$c120==3] <- 0.5
cmps$racial.eff.elected[cmps$c120==4] <- 0.25
cmps$racial.eff.elected[cmps$c120==5] <- 0

cmps$racial.efficacy <- NA
cmps$racial.efficacy <- as.numeric(cmps$racial.efficacy)
cmps$racial.efficacy <- ((cmps$racial.eff.officials)+(cmps$racial.eff.government)+(cmps$racial.eff.elected))/3
addmargins(prop.table(table(cmps$racial.efficacy)))


#MAIN DEPENDENT VARIABLES
cmps$ppact <- NA
cmps$ppact <- as.numeric(cmps$ppact)
cmps$ppact <- ((cmps$vote)+(cmps$donate)+(cmps$campwork)+
                 (cmps$comm_mtg)+(cmps$comm_work)+(cmps$contactpers)+
                 (cmps$protest)+(cmps$petition)+(cmps$boycott))/9

cmps$ppconventional <- NA
cmps$ppconventional <- as.numeric(cmps$ppconventional)
cmps$ppconventional <- ((cmps$vote)+(cmps$donate)+(cmps$campwork)+
                          (cmps$comm_mtg)+(cmps$comm_work)+(cmps$contactpers))/6


## SUBSET BY RACE AND CITIZENSHIP STATUS
asian.american <- subset(cmps, subset=(ethnic_quota==4))
asian.american.citizen <- subset(cmps, subset=(ethnic_quota==4&citizen2==1))
latinos <- subset(cmps, subset=(ethnic_quota==2))
latino.citizen <- subset(cmps, subset=(ethnic_quota==2&citizen2==1))
afam <- subset(cmps, subset=(ethnic_quota==3))
afam.citizen <- subset(cmps, subset=(ethnic_quota==3&citizen2==1))
white <- subset(cmps,subset=(ethnic_quota==1))
white.citizen <- subset(cmps, subset=(ethnic_quota==1&citizen2==1))

asian.white <- subset(cmps, subset=(asian==1|whites==1))
asian.white.citizen <- subset(asian.white, subset=(citizen==1))
black.white <- subset(cmps, subset=(black==1|whites==1))
black.white.citizen <- subset(black.white, subset=(citizen==1))
latinx.white <- subset(cmps, subset=(latino==1|whites==1))
latinx.white.citizen <- subset(latinx.white, subset=(citizen==1))

#CREATE TABLE 1
re.white <- lm(racial.efficacy~
                 income+education+age.new+female+democrat+partystrength+
                 polinterest+trust+protestant+catholic+churchattendance+non.straight+economy.worsened+intefficacy+extefficacy+
                 lf+discr.personal+
                 race.perceived+belonging+american.id+discr.whites.blacks.diff,data=white
               , weights=white$weight)

summary(re.white)

re.black <- lm(racial.efficacy~
                 income+education+age.new+female+democrat+partystrength+
                 polinterest+trust+protestant+catholic+churchattendance+non.straight+economy.worsened+intefficacy+extefficacy+
                 lf+discr.personal+
                 race.perceived+belonging+american.id+discr.blacks+
                 racial.equity.achieved+police.unfair+
                 black.org
               ,data=afam
               , weights=afam$weight)
summary(re.black)

#CREAte TABLE 2
re.latino <- lm(racial.efficacy~
                  income+education+age.new+female+democrat+partystrength+
                  polinterest+trust+protestant+catholic+churchattendance+non.straight+economy.worsened+intefficacy+extefficacy+
                  lf+discr.personal+race.perceived+belonging+american.id+first.gen+discr.latinos+racial.equity.achieved+police.unfair+afro.latino+colombian+cuban+dominican+mexican+puerto.rican+spanish
                ,data=latinos,
                weight=latinos$weight)
summary(re.latino)

re.asian <- lm(racial.efficacy~
                 income+education+age.new+female+democrat+partystrength+
                 polinterest+trust+protestant+catholic+churchattendance+non.straight+economy.worsened+intefficacy+extefficacy+
                 lf+discr.personal+
                 race.perceived+belonging+american.id+first.gen+discr.asians+
                 racial.equity.achieved+police.unfair+chinese+taiwanese+indian+korean+filipino+vietnamese+japanese,data=asian.american
               , weights=asian.american$weight)
summary(re.asian)

##CREATE FIGURE 1

#internal efficacy
weighted.mean(white$intefficacy, white$weight, na.rm=TRUE)
weighted.mean(afam$intefficacy, afam$weight, na.rm=TRUE)
weighted.mean(asian.american$intefficacy, asian.american$weight, na.rm=TRUE)
weighted.mean(latinos$intefficacy, latinos$weight, na.rm=TRUE)

#external efficacy
weighted.mean(white$extefficacy, white$weight, na.rm=TRUE)
weighted.mean(afam$extefficacy, afam$weight, na.rm=TRUE)
weighted.mean(asian.american$extefficacy, asian.american$weight, na.rm=TRUE)
weighted.mean(latinos$extefficacy, latinos$weight, na.rm=TRUE)

#racial efficacy
weighted.mean(white$racial.efficacy, white$weight, na.rm=TRUE)
weighted.mean(afam$racial.efficacy, afam$weight, na.rm=TRUE)
weighted.mean(asian.american$racial.efficacy, asian.american$weight, na.rm=TRUE)
weighted.mean(latinos$racial.efficacy, latinos$weight, na.rm=TRUE)

###CREEAT TABLE 3 AND FIGURE 2
ppact.white <- lm(ppact~racial.efficacy+intefficacy+extefficacy+lf+
                    income+education+age.new+female+democrat+partystrength+
                    polinterest+trust+churchattendance+economy.worsened+forborn,
                  weights=white$weight,
                  data=white)
summary(ppact.white)
get_model_data(ppact.white,type="eff")

ppact.black <- lm(ppact~racial.efficacy+intefficacy+extefficacy+lf+
                    income+education+age.new+female+democrat+partystrength+
                    polinterest+trust+churchattendance+economy.worsened+forborn,
                  weights=afam$weight,
                  data=afam)
summary(ppact.black)
get_model_data(ppact.black,type="eff")


ppact.latinx <- lm(ppact~racial.efficacy+intefficacy+extefficacy+lf+
                     income+education+age.new+female+democrat+partystrength+
                     polinterest+trust+churchattendance+economy.worsened+forborn,
                   data=latinos, weights=latinos$weight)
summary(ppact.latinx)
get_model_data(ppact.latinx,type="eff")


ppact.asian <- lm(ppact~racial.efficacy+intefficacy+extefficacy+lf+
                    income+education+age.new+female+democrat+partystrength+
                    polinterest+trust+churchattendance+economy.worsened+forborn,
                  weights=asian.american$weight,
                  data=asian.american)
summary(ppact.asian)
get_model_data(ppact.asian,type="eff")

##CREATE FIGURE 3
ppconv.white <- lm(ppconventional~racial.efficacy+intefficacy+extefficacy+lf+
                     income+education+age.new+female+democrat+partystrength+
                     polinterest+trust+churchattendance+economy.worsened+forborn,
                   weights=white$weight,
                   data=white)
summary(ppconv.white)
get_model_data(ppconv.white,type="eff")


ppconv.black <- lm(ppconventional~racial.efficacy+intefficacy+extefficacy+lf+
                     income+education+age.new+female+democrat+partystrength+
                     polinterest+trust+churchattendance+economy.worsened+forborn,
                   weights=afam$weight,
                   data=afam)
summary(ppconv.black)
get_model_data(ppconv.black,type="eff")

ppconv.latinx <- lm(ppconventional~racial.efficacy+intefficacy+extefficacy+lf+
                      income+education+age.new+female+democrat+partystrength+
                      polinterest+trust+churchattendance+economy.worsened+forborn,
                    data=latinos, weights=latinos$weight)
summary(ppconv.latinx)
get_model_data(ppconv.latinx,type="eff")

ppconv.asian <- lm(ppconventional~racial.efficacy+intefficacy+extefficacy+lf+
                     income+education+age.new+female+democrat+partystrength+
                     polinterest+trust+churchattendance+economy.worsened+forborn,
                   weights=asian.american$weight,
                   data=asian.american)
summary(ppconv.asian)
get_model_data(ppconv.asian,type="eff")


#CREATE FIGURE 4
ppunconv.white <- lm(ppunconv~racial.efficacy+intefficacy+extefficacy+lf+
                       income+education+age.new+female+democrat+partystrength+
                       polinterest+trust+churchattendance+economy.worsened+forborn,
                     data=white, weights=white$weight)
summary(ppunconv.white)
get_model_data(ppunconv.white,type="eff")

ppunconv.black <- lm(ppunconv~racial.efficacy+intefficacy+extefficacy+lf+
                       income+education+age.new+female+democrat+partystrength+
                       polinterest+trust+churchattendance+economy.worsened+forborn,
                     data=afam, weights=afam$weight)
summary(ppunconv.black)
get_model_data(ppunconv.black,type="eff")

ppunconv.latinx <- lm(ppunconv~racial.efficacy+intefficacy+extefficacy+lf+
                        income+education+age.new+female+democrat+partystrength+
                        polinterest+trust+churchattendance+economy.worsened+forborn,
                      data=latinos, weights=latinos$weight)
summary(ppunconv.latinx)
get_model_data(ppunconv.latinx,type="eff")

ppunconv.asian <- lm(ppunconv~racial.efficacy+intefficacy+extefficacy+lf+
                       income+education+age.new+female+democrat+partystrength+
                       polinterest+trust+churchattendance+economy.worsened+forborn,
                     data=asian.american, weights=asian.american$weight)
summary(ppunconv.asian)
get_model_data(ppunconv.asian,type="eff")